package com.wing.ext.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.wing.common.CommonSpringJDBC;
import com.wing.common.util.PageBean;
import com.wing.ext.domain.Products;

@Repository
public class ProductsDao extends CommonSpringJDBC<Products, String> {

	public PageBean findPageList(int currentPage, int pageSize, Object... args) {
		String where= null;
		if(args.length == 1){
			where= "groupid= '"+args[0]+"'";
		}else{
			if(args[0].equals("ROOT")){
				where= "site_id = '"+args[1]+"'";
			}else{
				where= "groupid= '"+args[0]+"' and site_id = '"+args[1]+"'";
			}
		}

		String sql1=" SELECT * FROM ext_products where "+where+" ORDER BY id ASC " +
			" LIMIT "+(currentPage-1) * pageSize+","+pageSize;
		String sql2 = "select count(id) from  ext_products  where "+where;
		String[] sqlArray = {sql1,sql2 };
		return super.findPageList(sqlArray, currentPage, pageSize);
	}
	
	public List findProductsByGrpId(String grpId) {
		String where= "groupid= '"+grpId+"'";
		String sql=" SELECT * FROM ext_products where "+where+" ORDER BY id ASC ";
		return this.getSimpleJdbcTemplate().queryForList(sql);
	}
	
}
